{include file="public/nheader" /}
<div class="layui-fluid layui-bg-white">
    <form action="{:url()}" class="layui-form layui-form-fixed">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>会员名称
            </label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" required="" lay-verify="required" autocomplete="off"
                    class="layui-input" value="{$row.name|default=''}" placeholder="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>开关
            </label>
            <div class="layui-input-block">
                <input type="radio" name="isopen" value="1" title="关闭" {if !empty($row.isopen) &&
                    $row.isopen==1}checked{/if}>
                <input type="radio" name="isopen" value="2" title="开放" {if !empty($row.isopen) &&
                    $row.isopen==2}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>会员折扣(单位:%)
            </label>
            <div class="layui-input-block">
                <input type="number" id="zhekou" name="zhekou" required="" lay-verify="required" autocomplete="off"
                    class="layui-input" value="{$row.zhekou|default='100'}" placeholder="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>购买会员价格(单位:元)
            </label>
            <div class="layui-input-block">
                <input type="number" id="money" name="money" required="" lay-verify="required" autocomplete="off"
                    class="layui-input" value="{$row.money|default='100'}" placeholder="">
            </div>
        </div>
        <div class="layui-card layui-form">
            <label class="layui-form-label">
                赠送抵扣券
            </label>
            <div class="layui-card-body">
                <div class="layui-input-block">
                    <a class="layui-btn layui-btn-btn layui-btn-sm layui-btn-normal" onclick="addtable()">添加券</a>
                    <table class="layui-table layui-form" style="border:1px solid #ccc;" id="table" lay-filter="table">
                        <thead>
                            <tr>
                                <td>
                                    <div class="layui-table-cell">序号</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">可用鞋类型</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">有效期天数</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">补贴金额</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">操作</div>
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                            {if !empty($row.coupons)}
                            {foreach $row.coupons as $k => $v}
                            <tr style="width:100px">
                                <td>{$k+1}</td>
                                <td>
                                    {foreach :config()['config']['type'] as $s => $vs}
                                    {if $s > 0}
                                    <input name="coupons[{$k}][type][]" {if in_array($s, $v.type)} checked {/if}
                                        lay-skin="primary" type="checkbox" value="{$s}" title="{$vs}"><br />
                                    {/if}
                                    {/foreach}
                                </td>
                                <td><input required="" lay-verify="required" type="text" id="layui-input"
                                        class="layui-input" name="coupons[{$k}][days]" value="{$v.days|default=0}"></td>
                                <td><input required="" lay-verify="required" type="text" id="layui-input"
                                        class="layui-input" name="coupons[{$k}][money]" value="{$v.money|default=0}">
                                </td>
                                <td><a class="layui-btn layui-btn-danger layui-btn-xs del">删除</a></td>
                            </tr>
                            {/foreach}
                            {/if}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <div class="layui-card layui-form">
            <label class="layui-form-label">
                赠送优惠券
            </label>
            <div class="layui-card-body">
                <div class="layui-input-block">
                    <a class="layui-btn layui-btn-btn layui-btn-sm layui-btn-normal" onclick="addtable2()">添加</a>
                    <table class="layui-table layui-form" style="border:1px solid #ccc;" id="table2"
                        lay-filter="table2">
                        <thead>
                            <tr>
                                <td>
                                    <div class="layui-table-cell">需要达到使用金额(单位:元)</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">抵扣金额(单位:元)</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">有效时长(单位:天)</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">操作</div>
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                            {if !empty($row.coupon)}
                            {foreach $row.coupon as $k => $v}
                            <tr>
                                <td><input required="" lay-verify="required" type="text" id="layui-input"
                                        class="layui-input" name="parpam[{$k}][getmoney]" value="{$v.getmoney}">
                                </td>
                                <td><input required="" lay-verify="required" type="text" id="layui-input"
                                        class="layui-input" name="parpam[{$k}][money]" value="{$v.money}">
                                </td>
                                <td><input required="" lay-verify="required" type="text" id="layui-input"
                                        class="layui-input" name="parpam[{$k}][days]" value="{$v.days}">
                                </td>
                                <td>
                                    <a class="layui-btn layui-btn-danger layui-btn-xs del2">删除</a>
                                </td>
                            </tr>
                            {/foreach}
                            {/if}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>权益说明
            </label>
            <div class="layui-input-block">
                <textarea id="contents" name="contents" />{$row.contents|default=''}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>协议说明
            </label>
            <div class="layui-input-block">
                <textarea id="protocol" name="protocol" />{$row.protocol|default=''}</textarea>
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <input type="hidden" value="{$row['id']|default='0'}" name="id" />
            <button class="layui-btn" lay-filter="submitIframe" type="button" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closeDialog">取消</button>
        </div>
    </form>
</div>
{include file="public/nfooter" /}
<script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script>
    layui.use(['form', 'jquery', 'layedit', 'admin', 'content'], function () {
        var form = layui.form;
        var admin = layui.admin;
        var jquery = layui.jquery;
        // 渲染富文本编辑器
        var layedit = layui.layedit;
        var content = layui.content;
        content.tinymce('contents');
        content.tinymce('protocol');
    });
    function addtable() {
        var i = $('#table tbody tr').length;
        var json = {
            "1": "儿童鞋",
            "2": "高邦运动鞋",
            "3": "高筒靴",
            "4": "马丁靴",
            "5": "跑步鞋",
            "6": "足球鞋",
            "7": "网面鞋",
            "8": "篮球鞋",
            "9": "皮鞋",
            "10": "板鞋",
            "11": "小白鞋",
            "12": "半筒靴",
            "13": "低邦帆布鞋",
            "14": "高邦帆布鞋",
            "99": "修理洗护调整"
        };
        var check = '';
        var checked = 'checked';
        $.each(json, function (m, obj) {
            console.log(m);
            if (m == 99) {
                checked = '';
            }
            check += '<input name="coupons[' + i + '][type][]" lay-skin="primary" ' + checked + ' type="checkbox" value="' + m + '" title="' + obj + '" ><br/>'
        });
        //你要添加的html
        var html = '<tr ><td>' + (i + 1) + '</td><td>' + check + '</td>' +
            '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="coupons[' + i + '][days]" value="365"></td>' +
            '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="coupons[' + i + '][money]" value="9.96"></td>' +
            '<td><a class="layui-btn layui-btn-danger layui-btn-xs del2" >删除</a></td></tr>';
        $(html).appendTo($('#table tbody:last'));
        layui.use(['form'], function () {
            $ = layui.jquery;
            var form = layui.form;
            form.render();
        });
    };
    function addtable2() {
        var i = $('#table2 tbody tr').length;
        //你要添加的html
        var html = '<tr>' +
            '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="parpam[' + i + '][getmoney]" value=""></td>' +
            '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="parpam[' + i + '][money]" value=""></td>' +
            '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="parpam[' + i + '][days]" value=""></td>' +
            '<td><a class="layui-btn layui-btn-danger layui-btn-xs del2" >删除</a></td></tr>';
        $(html).appendTo($('#table2 tbody:last'));
        layui.use(['form'], function () {
            $ = layui.jquery;
            var form = layui.form;
            form.render();
        });
    };
    $('body').on('click', '.del2', function () {
        $(this).closest('tr').remove();
    });
    $('body').on('click', '.del', function () {
        $(this).closest('tr').remove();
    });
</script>